<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">{{ $t('pallet.palletCode') }}</label>
        <el-input
          v-model="query.palletCode"
          clearable
          :placeholder="$t('pallet.palletCode')"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <label class="el-form-item-label">{{ $t('pallet.palletSize') }}</label>
        <el-input
          v-model="query.palletSize"
          clearable
          :placeholder="$t('pallet.palletSize')"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="35%"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="auto">
          <el-form-item :label="$t('pallet.palletCode')" prop="palletCode">
            <el-input v-model="form.palletCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('pallet.palletSize')">
            <el-input v-model="form.palletSize" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('pallet.processcardId')">
            <el-input v-model="form.processcardId" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('pallet.flowTo')">
            <el-input v-model="form.flowTo" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('pallet.layUpStationCode')">
            <el-input v-model="form.layUpStationCode" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">{{ $t('crud.cancel') }}</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">{{ $t('crud.confirm') }}</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" :label="$t('pallet.id')" />
        <el-table-column prop="palletCode" :label="$t('pallet.palletCode')" />
        <el-table-column prop="palletSize" :label="$t('pallet.palletSize')" />
        <el-table-column prop="palletLocation" :label="$t('pallet.palletLocation')" />
        <el-table-column prop="createTime" :label="$t('pallet.createTime')" />
        <el-table-column prop="createBy" :label="$t('pallet.createBy')" />
        <el-table-column prop="updateTime" :label="$t('pallet.updateTime')" />
        <el-table-column prop="updateBy" :label="$t('pallet.updateBy')" />
        <el-table-column prop="processcardId" :label="$t('pallet.processcardId')" />
        <el-table-column prop="flowTo" :label="$t('pallet.flowTo2')">
          <template slot-scope="scope">
            {{ dict.label.flowto[scope.row.flowTo] }}
          </template>
        </el-table-column>
        <el-table-column prop="layUpStationCode" :label="$t('pallet.layUpStationCode')" />
        <el-table-column
          v-if="checkPer(['admin', 'pallet:edit', 'pallet:del'])"
          :label="$t('common.operation')"
          width="150px"
          align="center"
        >
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudPallet from '@/api/pallet'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import i18n from '@/lang'
const defaultForm = { id: null, palletCode: null, palletSize: null, palletLocation: null, createTime: null, createBy: null, updateTime: null, updateBy: null, processcardId: null, flowTo: null, layUpStationCode: null }
export default {
  name: 'Pallet',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['flowto'],
  cruds() {
    return CRUD({ title: '载盘', url: 'api/pallet', idField: 'id', sort: 'id,desc', crudMethod: { ...crudPallet }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'pallet:add'],
        edit: ['admin', 'pallet:edit'],
        del: ['admin', 'pallet:del']
      },
      rules: {
        palletCode: [
          { required: true, message: i18n.t('rules.palletCodeValidation'), trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'palletCode', display_name: '载盘编码' },
        { key: 'palletSize', display_name: '载盘尺寸' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped></style>
